<template>
	<view>
		<view class="pl-30 pr-30 pt-45">
			<u-field v-model="password" type="number" label="支付密码" maxlength="6" label-width="180" input-align="right"
				placeholder="请输入您的支付密码">
			</u-field>
		</view>
		<view class="pl-30 pr-30">
			<u-field v-model="captcha" label="验证码" maxlength="6" placeholder="请输入验证码">
				<u-button size="mini" slot="right" class="btn-code" type="success" @click="getCode">{{codeText}}</u-button>
			</u-field>
			<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
		</view>
		<view class="mt-120 pl-30 pr-30">
			<u-button class="bank-btn" hover-class="none" @click="submit">提交</u-button>
		</view>
		<!-- <u-keyboard ref="uKeyboard" v-model="show"></u-keyboard> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				captcha: '', //
				codeText: '获取验证码'
			};
		},
		methods: {
			submit() {
				if (!this.password || this.password.length != 6) return this.$u.toast(`请输入六位数的支付密码`);
				if (!this.captcha) return this.$u.toast(`请输入验证码`);
				this.$http('api/newapi/passUp', {
					password: this.password,
					captcha:this.captcha
				}).then(res => {
					this.$u.toast(`修改成功`);
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				}).catch(err => {
					
				})
			},
			codeChange(text) {
				this.codeText = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$http('api/login/sendCode', {
						phone: this.phone,
						type: 6
					}, 'POST').then(data => {
						uni.showToast({
							title: "发送成功",
							icon: 'none'
						})
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}).catch(() => {
						
					})
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			getUserInfo () {
				this.$http('api/user/userInfo').then(res => {
				  this.phone = res.phone
				})
			},
		},
		onLoad() {
			this.getUserInfo()
		}
	}
</script>
<style>
	page {
		background: #f5f5f5;
	}
</style>
<style lang="scss">
	/deep/ .u-label-text,
	/deep/ .uni-input-input {
		color: #282828;
	}

	.bank-btn {
		color: #fff !important;
		font-size: 30rpx;
		line-height: 88rpx;
		height: 88rpx !important;
		background: linear-gradient(90deg, #EEA634, #DE2D32);
		border-radius: 44rpx;

		&::after {
			border: none !important;
		}
	}
	.btn-code {
		width: 190rpx;
		height: 60rpx;
		background: #30314395 !important;
		border-radius: 30rpx;
	}
</style>
